

const isPcClient = !!window.AppInfo;
const BASE_WIDTH = 1920;
const BASE_FONTSIZE = 100;

export const getRem = (zoomFactor = 1) => {
    const vw = isPcClient ? 1400 : document.documentElement.getBoundingClientRect().width;
    const zoomFontSize = zoomFactor * BASE_FONTSIZE;
    return Math.ceil((vw / BASE_WIDTH) * zoomFontSize);
};

/**
 * 刷新 font-size 以适配当前视口
 * @param zoomFactor
 */
export const refreshRem = (zoomFactor = 1) => {
    const zoomFontSize = zoomFactor * BASE_FONTSIZE;
    const rem = getRem(zoomFactor);
    document.documentElement.style.fontSize = `${rem}px`;
    document.documentElement.setAttribute("data-dpr", String(Math.floor(rem / zoomFontSize)));
};

refreshRem(1.28)